package com.demo.web;

import java.util.Map;

import com.demo.server.IndexServer;
import com.demo.web.base.BaseResult;
import com.jweb.annotaion.JAutowired;
import com.jweb.annotaion.JController;
import com.jweb.annotaion.JValue;
import com.jweb.core.JWebFilter;
import com.jweb.core.handle.Controller;
import com.jweb.log.Logger;
import com.jweb.plugin.dynamicdatasource.DataSourceHolder;
import com.jweb.plugin.jdbc.JdbcTemplate;
import com.jweb.util.FormatUtil;

/**
 * 登录
 * 
 * @author Yuan
 *
 */
@JController("/index")
public class IndexController extends Controller {
	private Logger log = Logger.getLogger(this.getClass());
	@JAutowired
	private IndexServer server;

	@JValue("ViewPrefix")
	private String ViewPrefix;

	public void init() {

		try {
			JdbcTemplate jt = JWebFilter.getJdbctemplate();
			DataSourceHolder.setDbType("read");
			System.err.println("当前数据库read::" + jt.query("SELECT VERSION()", null).toString());
			// DataSourceHolder.setDbType("write");
			// System.err.println("当前数据库write::" + jt.query("SELECT VERSION()",
			// null).toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void IndexManager() {
		log.info("来了一个首页访问请求。");
		int currentPage = FormatUtil.toInt(request.get().getParameter("currentPage"), 1);
		String licenseNumber = FormatUtil.toStringTrim(request.get().getParameter("licenseNumber"));
		String companyName = FormatUtil.toStringTrim(request.get().getParameter("companyName"));
		String busType = FormatUtil.toStringTrim(request.get().getParameter("busType"));
		int batch = FormatUtil.toInt(request.get().getParameter("batch"), 0);
		BaseResult<Map<String, String>> baseResult = server.listPayCompant(currentPage, licenseNumber, companyName, busType, batch);
		setAttr("result", baseResult);
		// log.info("方法里面也可以什么都不写，默认跳到 testLogin.jsp页面");
	}
}
